package com.epfresh.bean;

import android.util.Log;

import java.util.List;

/**
 * Created by wzh on 16-8-29.
 */
public class MarketCart {
    private String salesType;
    private double freight;

    private String wholeSaleMarketId;
    private String storeOrMarketName;
    private String wholeSaleMarketFullName;
    private List<CartGood> productList;
    private List<DeliveryModes> deliveryList;
    private List<Dc> distributionList;
    private List<DeliveryDate> deliveryDateList;
    private DeliveryDate deliveryDateDef;
    private boolean isDeliverySelect = true;
    private boolean isMerchantDeliverySelect = true;

    private String distributionId;
    private String distributionTitle;
    private String distributionName;

    private String feed;
    //运费起步价
    private float productExpressFeeStartingPrice;

    private boolean overScope;
    private boolean overScopeNew;
    private Integer wholeSalesType;

    private boolean isExpend;

    private Double economizePrice;//折扣扣节省小计
    private String discountStr;//店铺折扣信息


    //原始运费
    private double productExpressFeeOriginal;
    //减免运费
    private Double productExpressFeeReduce;
    private double productExpressFee;

    public boolean isOverScopeNew() {
        return overScopeNew;
    }

    public void setOverScopeNew(boolean overScopeNew) {
        this.overScopeNew = overScopeNew;
    }

    public double getFreight() {
        return freight;
    }

    public void setFreight(double freight) {
        this.freight = freight;
    }

    public String getSalesType() {
        return salesType;
    }

    public void setSalesType(String salesType) {
        this.salesType = salesType;
    }

    public double getProductExpressFee() {
        return productExpressFee;
    }

    public void setProductExpressFee(double productExpressFee) {
        this.productExpressFee = productExpressFee;
    }

    public double getProductExpressFeeOriginal() {
        return productExpressFeeOriginal;
    }

    public void setProductExpressFeeOriginal(double productExpressFeeOriginal) {
        this.productExpressFeeOriginal = productExpressFeeOriginal;
    }

    public Double getProductExpressFeeReduce() {
        return productExpressFeeReduce;
    }

    public void setProductExpressFeeReduce(Double productExpressFeeReduce) {
        this.productExpressFeeReduce = productExpressFeeReduce;
    }

    public Double getEconomizePrice() {
        return economizePrice;
    }

    public void setEconomizePrice(Double economizePrice) {
        this.economizePrice = economizePrice;
    }

    public String getDiscountStr() {
        return discountStr;
    }

    public void setDiscountStr(String discountStr) {
        this.discountStr = discountStr;
    }

    public boolean isExpend() {
        return isExpend;
    }

    public void setExpend(boolean expend) {
        isExpend = expend;
    }


    public float getProductExpressFeeStartingPrice() {
        return productExpressFeeStartingPrice;
    }

    public void setProductExpressFeeStartingPrice(float productExpressFeeStartingPrice) {
        this.productExpressFeeStartingPrice = productExpressFeeStartingPrice;
    }

    public void setOverScope(boolean overScope) {
        this.overScope = overScope;
    }

    public Integer getWholeSalesType() {
        return wholeSalesType == null ? 1 : wholeSalesType;
    }

    public void setWholeSalesType(Integer wholeSalesType) {
        this.wholeSalesType = wholeSalesType;
    }

    public void setFeed(String feed) {
        this.feed = feed;
    }

    public String getWholeSaleMarketId() {
        return wholeSaleMarketId;
    }

    public void setWholeSaleMarketId(String wholeSaleMarketId) {
        this.wholeSaleMarketId = wholeSaleMarketId;
    }

    public void setStoreOrMarketName(String storeOrMarketName) {
        this.storeOrMarketName = storeOrMarketName;
    }


    public void setWholeSaleMarketFullName(String wholeSaleMarketFullName) {
        this.wholeSaleMarketFullName = wholeSaleMarketFullName;
    }

    public List<CartGood> getProductList() {
        return productList;
    }

    public void setProductList(List<CartGood> productList) {
        this.productList = productList;
    }

    public List<DeliveryModes> getDeliveryList() {
        return deliveryList;
    }

    public void setDeliveryList(List<DeliveryModes> deliveryList) {
        this.deliveryList = deliveryList;
    }

    public List<Dc> getDistributionList() {
        return distributionList;
    }

    public void setDistributionList(List<Dc> distributionList) {
        this.distributionList = distributionList;
    }

    public List<DeliveryDate> getDeliveryDateList() {
        return deliveryDateList;
    }

    public void setDeliveryDateList(List<DeliveryDate> deliveryDateList) {
        this.deliveryDateList = deliveryDateList;
    }

    public boolean isDeliverySelect() {
        return isDeliverySelect;
    }

    public void setDeliverySelect(boolean deliverySelect) {
        isDeliverySelect = deliverySelect;
    }

    public boolean isMerchantDeliverySelect() {
        return isMerchantDeliverySelect;
    }

    public void setMerchantDeliverySelect(boolean merchantDeliverySelect) {
        isMerchantDeliverySelect = merchantDeliverySelect;
    }

    public DeliveryDate getDeliveryDateDef() {
        return deliveryDateDef;
    }

    public void setDeliveryDateDef(DeliveryDate deliveryDateDef) {
        this.deliveryDateDef = deliveryDateDef;
    }

    public String getDistributionId() {
        return distributionId;
    }

    public void setDistributionId(String distributionId) {
        this.distributionId = distributionId;
    }

    public String getDistributionTitle() {
        return distributionTitle;
    }

    public void setDistributionTitle(String distributionTitle) {
        this.distributionTitle = distributionTitle;
    }

    public String getDistributionName() {
        return distributionName;
    }

    public void setDistributionName(String distributionName) {
        this.distributionName = distributionName;
    }

    public float getFeed() {
        float f = 0f;
        if (feed != null && !"null".equals(feed)) {
            f = Float.valueOf(feed);
        }
        //小于起步价
        if (f < productExpressFeeStartingPrice){
            f = productExpressFeeStartingPrice;
        }
        return f;
    }

    public void setFeed(float feed) {
        this.feed = feed + "";
    }

    public String getDeliveryMode() {

        if (isDeliverySelect) {

            if (deliveryList != null) {
                for (int i = 0; i < deliveryList.size(); i++) {
                    DeliveryModes deliveryModes = deliveryList.get(i);
                    String code = deliveryModes.getCode();

                    if ("gatherDistribution".equals(code)) {//集单配送
                        return "gatherDistribution";
                    }
                }
            }
        }
        if (isMerchantDeliverySelect) {
            return "merchantDelivery";
        }
        return "selfDelivery";
    }

    public boolean isOnlySelf(){

        for (int i = 0; i < deliveryList.size(); i++) {
            DeliveryModes deliveryModes = deliveryList.get(i);
            String code = deliveryModes.getCode();

            if ("gatherDistribution".equals(code)) {//集单配送
                return false;
            } else if ("selfDelivery".equals(code)) {

            }
        }

        return true;
    }

    public void init() {
        if (deliveryList != null) {
            for (int i = 0; i < deliveryList.size(); i++) {
                DeliveryModes deliveryModes = deliveryList.get(i);
                String code = deliveryModes.getCode();

                if ("gatherDistribution".equals(code)) {//集单配送
                    isDeliverySelect = true;
                    return;
                } else if ("selfDelivery".equals(code) && getWholeSalesType() == 1) {

                    isDeliverySelect = false;
                }
            }
        }
    }

    public void initDistribution() {

        setDeliveryDateDef(getDefDeliveryDate());
        initFee();
        init();
        if (distributionList != null && distributionList.size() > 0) {
            for (int i = 0; i < distributionList.size(); i++) {

                Dc dc = distributionList.get(i);
                if (dc != null && (i == 0 || dc.isDefault())) {
                    distributionId = dc.getId();
                    distributionName = dc.getTitle();
                }
            }
        }
    }

    public void initFee() {
        if (productList != null) {
            for (int i = 0; i < productList.size(); i++) {
                CartGood cartGood = productList.get(i);
                String productExpressFee = cartGood.getProductExpressFee();
                if (productExpressFee != null && productExpressFee.length() > 0) {

                    if (feed == null|| "".equals(feed)){
                        feed = "0";
                    }
                    feed = (Float.valueOf(feed) + Float.valueOf(productExpressFee))+"";
                }

            }
        }
    }

    public boolean isDeliveryOverScope(){
        if (deliveryList == null || deliveryList.size() == 0){
            //没有配送方式
            return true;
        }
//        if (deliveryList != null && deliveryList.size() > 0){
        for (int i = 0; i < deliveryList.size(); i++) {
            DeliveryModes deliveryModes = deliveryList.get(i);
            String code = deliveryModes.getCode();

            if ("gatherDistribution".equals(code)) {//集单配送
                return false;
            } else if ("selfDelivery".equals(code)) {
                return false;
            } else if ("merchantDelivery".equals(code)) {
                return false;
            }
        }
//        }

        return true;
//        return /*getWholeSalesType() == 2 &&*/ isOverScope();
    }
    public boolean isOverScope() {
        boolean isOverScope = true;

        if (deliveryList != null && deliveryList.size() > 0){
            for (int i = 0; i < deliveryList.size(); i++) {
                DeliveryModes deliveryModes = deliveryList.get(i);
                String code = deliveryModes.getCode();

                if ("gatherDistribution".equals(code)) {//集单配送
                    isOverScope = false;
                } else if ("selfDelivery".equals(code)) {
//                    isOverScope = false;
                }
            }
        }
        Log.e("cartGoods.isOverScope()",isOverScope+"");
        return overScope || isOverScope;
    }

    public String getStoreOrMarketName() {

/*        if ((storeOrMarketName == null || "".equals(storeOrMarketName)
                || "null".equals(storeOrMarketName)) && wholeSaleMarketFullName != null && !"".equals(wholeSaleMarketFullName)) {
            return wholeSaleMarketFullName;
        }*/
        return storeOrMarketName == null ? "" : storeOrMarketName;
    }

    public String getWholeSaleMarketFullName() {
        if ((wholeSaleMarketFullName == null || "".equals(wholeSaleMarketFullName) || "null".equals(wholeSaleMarketFullName)) && storeOrMarketName != null && !"".equals(storeOrMarketName)) {
            return storeOrMarketName;
        }
        return wholeSaleMarketFullName == null ? "" : wholeSaleMarketFullName;
    }

    public DeliveryDate getDefDeliveryDate() {
        if (deliveryDateList != null && deliveryDateList.size() > 0) {
            return deliveryDateList.get(0);
        }
        return null;
    }

}
